<?php
/**
 * Created by 上海互教教育科技有限公司.
 * User: 刘红伟
 * QQ  : 454303753
 * Date: 2017/5/31 0031
 * Time: 下午 15:08
 */
namespace App\Http\Controllers\v1;
use App\Levels;
use Laravel\Lumen\Routing\Controller as BaseController;
use Illuminate\Http\Request;
class LevelsController extends BaseController
{
    public function add(Request $request)
    {

        if($request)
        {

            $level_obj  =  new Levels();
            $level_obj->name            =   $request->name;
            $level_obj->create_at       =   time();
            if($level_obj->save())
            {
                return response()->json(array('status'=>1),200);
            };

            return response()->json(array('status'=>0),200);

        }


    }


    public function get_data($level_id)
    {
        $levels =   Levels::find($level_id);
        if($levels)
        {
            return response()->json($levels,200);
        }else
        {
            return response()->json((object)array(),200);
        }

    }

    public function get_all()
    {
        $levels =   Levels::all();

        if($levels)
        {
            return response()->json($levels,200);
        }else
        {
            return response()->json((object)array(),200);
        }

    }

}